package com.pgp.demo.pgpexample.exception;
import org.apache.commons.lang3.exception.ExceptionUtils;
/**
 * 业务异常
 * @author Alan
 * @date 2022/11/04
 */
public final class BusinessException extends BaseException {

    /**
     * message返回 用户
     */
    public BusinessException(String message) {
        super(message);
    }

    /**
     * 错误code, message返回 用户
     */
    public BusinessException(String code, String message) {
        super(code, message);
    }

    public BusinessException(String code, String message, String errorMsg) {
        super(code, message);
        super.setDetailMessage(errorMsg);
    }
    /**
     * 业务异常
     * message: 返回用户
     * detailMessage: 记录数据库
     *
     * @param message 消息
     * @param e       e
     */
    public BusinessException(String message, Exception e) {
        super("90000", message);
        super.setDetailMessage(ExceptionUtils.getStackTrace(e));
    }

    public static BusinessException createDetailMessage(String message, String detailMessage) {
        BusinessException b = new BusinessException(message);
        b.setDetailMessage(detailMessage);
        return b;
    }

    @Override
    public String toString() {
        return String.format("BusinessException: code={%s}, message={%s}, detailMessage={%s}"
                , getCode()
                , getMessage()
                , getDetailMessage());
    }
}
